<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图片自适应一个div</title>
    <style>
        .img-box1 {
            height: 300px;
            width: 300px;
            background-color: pink;
        }
        .img-box1 img {
            width: 100%;
        }


        .img-box2 {
            height: 500px;
            width: 500px;
            background-color: greenyellow;
            position: relative;
        }
        .img-box2 img {
            height: 100%;
            position: absolute;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
            margin: auto;
           
        }
    </style>
</head>
<body>
    <div class="img-box1">
        <img src="http://img1.qunarzz.com/piao/fusion/1803/e3/67df61427c8e1302.png" alt="">
    </div>

     <div class="img-box2">
        <img src="http://img1.qunarzz.com/piao/fusion/1803/e3/67df61427c8e1302.png" alt="">
    </div>
    
</body>
</html>